package sf.actions;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

import sf.view.StandardForm;

public class ActionUnos extends SFAbstractAction {

	private static final long serialVersionUID = 1L;

	private StandardForm parentForm;

	ActionUnos(StandardForm parentForm) {
		this.parentForm = parentForm;
		putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U,
				ActionEvent.CTRL_MASK));
		putValue(MNEMONIC_KEY, KeyEvent.VK_U);
		putValue(SMALL_ICON, loadIcon("img/unos.png"));
		putValue(NAME, "Unos");
		putValue(SHORT_DESCRIPTION, "Unos");
	}

	public void actionPerformed(ActionEvent e) {
		if ((parentForm.getMode()&StandardForm.MODE_ADD) == 0) {
			parentForm.setMode(StandardForm.MODE_ADD);
			
			// za slucaj da je tabela filtrirana koristeci quick search, uklanja filter
			parentForm.getToolbar().getSearchField().setText(null);

			parentForm.getDetailsPane().clearAllFields();
			parentForm.getDetailsPane().unlockAllFields();
			parentForm.getDetailsPane().focusFirstField();

			parentForm.getDetailsPane().getToolbar().removeAll();
			parentForm.getDetailsPane().getToolbar().add(
					parentForm.getActionManager().getPotvrdaUnosaAction());
			parentForm.getDetailsPane().getToolbar().add(
					parentForm.getActionManager().getPonistiAction());
		}
	}

	public void setButtonMode(int mode) {
		if ((mode&StandardForm.MODE_SEARCH) != 0)
			this.setEnabled(false);
		else
			this.setEnabled(true);
	}
}
